<!--
 * @Author: 李天惊 uf_lee@163.com
 * @Date: 2022-08-15 16:45:26
 * @LastEditors: 李天惊 uf_lee@163.com
 * @LastEditTime: 2022-12-21 17:10:12
 * @FilePath: \grazlink20\uc_sys\src\views\Asset\Pasture\components\See.vue
 * Copyright (c) 2022 by 李天惊 uf_lee@163.com, All Rights Reserved. 
-->
<script setup lang="ts">
import { PropType } from 'vue'
import type { TableData } from '@/api/uc/org/types'
import { Descriptions } from '@/components/Descriptions'
import { useI18n } from '@/hooks/web/useI18n'
import { ElTag, ElImage } from 'element-plus'
// 获取字典
import { useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache()
const dict: any = wsCache.get('dict')
// 字典通过value获取label
const getDictLabel = (type, value) => {
  let data = dict[type].find((item) => {
    return item.value == value
  })
  return data ? data.label : ''
}
const { t } = useI18n()

defineProps({
  currentRow: {
    type: Object as PropType<Nullable<TableData>>,
    default: () => null
  },
  detailSchema: {
    type: Array as PropType<DescriptionsSchema[]>,
    default: () => []
  }
})
</script>

<template>
  <div>
    <Descriptions :schema="detailSchema" :data="currentRow || {}">
      <template #is_stop="{ row }: { row: TableData }">
        <ElTag :type="row.is_stop === '0' ? 'success' : row.is_stop === '1' ? 'warning' : 'danger'">
          {{
            row.is_stop === '0' ? '启用' : row.is_stop === '1' ? '停用' : t('tableDemo.commonly')
          }}
        </ElTag>
      </template>

      <template #org_type="{ row }: { row: TableData }">
        <div>{{ getDictLabel('org_type', row.org_type) }}</div>
      </template>
      <template #state="{ row }: { row: TableData }">
        <div>{{ getDictLabel('org_state', row.state) }}</div>
      </template>

      <template #business_license="{ row }: { row: TableData }">
        <ElImage v-if="row.business_license" :src="row.business_license" />
      </template>

      <template #identity_card_front="{ row }: { row: TableData }">
        <ElImage v-if="row.identity_card_front" :src="row.identity_card_front" />
      </template>

      <template #identity_card_back="{ row }: { row: TableData }">
        <ElImage v-if="row.identity_card_back" :src="row.identity_card_back" />
      </template>
    </Descriptions>
  </div>
</template>
